package org.getOffer;

import java.util.Arrays;

/**
 * @Author yu
 * @Date 2021/6/8
 */
public class Practice06 {

    public static void main(String[] args) {

        ListNode listNode=new ListNode(1);
        ListNode listNode1=new ListNode(3);
        ListNode listNode2=new ListNode(2);
        listNode.next=listNode1;
        listNode1.next=listNode2;
        System.out.println(Arrays.toString(reversePrint(listNode)));


    }

    public static int[] reversePrint(ListNode head) {

        if (head.next==null||head.next.next==null){
            return null;
        }

        ListNode curNode=head;
        ListNode nextNode,prev = null;
        int count=0;

        while(curNode != null){
            nextNode = curNode.next;
            curNode.next = prev;
            prev = curNode;
            curNode = nextNode;
            count++;
        }

        int[] nums = new int[count];


        for (int i = 0; i < count; i++) {
            nums[i] = prev.value;
            prev = prev.next;
        }
        return nums;

    }

}

class ListNode{

    int value;
    ListNode next;

    public ListNode(int value) {
        this.value = value;
    }

}
